﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OAPlatform.CommonHelper;

namespace OAPlatform.DomainModel.Model
{
    public class AuthenticatableEntity : BaseEntity, IAuthenticatable
    {
        protected List<Role> roles = new List<Role>();
        public List<Role> Roles
        {
            get
            {
                return roles;
            }
            set
            {
                roles = value;
            }
        }

        /// <summary>
        /// 测试实体是否具有指定的权限
        /// </summary>
        /// <param name="permissionKey">要测试的权限的标识</param>
        /// <returns>有权限返回true，否则返回false</returns>
        public virtual bool Authenticate(string permissionKey)
        {
            Check.Argument.IsNotNullOrEmpty(permissionKey, "权限键值");

            return Roles.Exists(set => set.Authenticate(permissionKey));
        }
    }
}
